package com.company.lagou.homework;

public class Array {

    public static void main(String[] args) {
        // 编程实现二维数组的声明和使用
        int[][] arr1 = new int[16][16];
        // 使用for循环控制打印的行数和列数
        int sum1 = 0;
        int sum2 = 0;
        for (int i = 0; i < arr1.length; i++) {
            for (int j = 0; j < arr1.length; j++) {
                arr1[i][j] = (int) (Math.random() * 100);
                arr1[i][0] += arr1[i][j];

            }
            // 打印每一行的累加
            System.out.println("第" + (i + 1) + "行的和为：" + arr1[i][0]);
        }

        for (int j = 0; j < arr1.length; j++) {
            for (int i = 0; i < arr1.length; i++) {
                arr1[i][j] = (int) (Math.random() * 100);
                arr1[0][j] += arr1[i][j];
            }
            // 打印每一列的累加
            System.out.println("第" + (j + 1) + "列的和为：" + arr1[0][j]);
        }


        for (int i = 0; i < arr1.length; i++) {
            for (int j = 0; j < arr1.length; j++) {
                arr1[i][j] = (int) (Math.random() * 100);
                if (i == j) {
                    sum1 += arr1[i][j];
                }
            }
                   sum2 = sum2 += arr1[arr1.length - i - 1][i];

        }



        // 打印左上角到右下角的累加和
        System.out.println("左上角到右下角的累加和为：" + sum1);
        //打印右上角到左下角的累加和
        System.out.println("右上角到左下角的累加和为：" + sum2);

    }

}